#include <bits/stdc++.h>
using namespace std;
int n, a[100005], dp[105][105][105], t;
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> t;
    while (t--) {
        memset(dp, 0xc0, sizeof(dp));
        cin >> n;
        a[0] = -'3'-'5';
        for (int i = 1; i <= n; i++) cin >> a[i];
        dp[1][1][0] = 0;
        dp[1][0][1] = 0;
        for (int i = 2; i <= n; i++)
            for (int j = 0; j < i; j++)
                for (int k = 0; k < i; k++) {
                    dp[i][j][i] = max(dp[i - 1][j][k] + a[i] * (int)(a[i] == a[k]), dp[i][j][i]);
                    dp[i][i][k] = max(dp[i - 1][j][k] + a[i] * (int)(a[i] == a[j]), dp[i][i][k]);
                }
        int ans = 0;
        for (int i = 0; i <= n; i++)
            ans = max({ans, dp[n][i][n], dp[n][n][i]});
        cout << ans << endl;
    }
    return 0;
}